package com.gang.easyexcel_demo;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.gang.easyexcel_demo.entity.Student;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Service
public class ExcelService {
    public List<Student> readExcel(MultipartFile file) throws IOException {
        List<Student> sd = new ArrayList<>();
        EasyExcel.read(file.getInputStream(), Student.class, new ReadListener<Student>() {
            @Override
            public void invoke(Student student, AnalysisContext analysisContext) {
                sd.add(student);
            }

            @Override
            public void doAfterAllAnalysed(AnalysisContext analysisContext) {

            }
        }).sheet("模板").doRead();
        return sd;
    }
}
